namespace :bld do
  desc "Export to image from database"
  task :export_to_img_sp => :environment do
     require 'csv'
    require 'lib/tasks/bili_ranking_image_sp.rb'
    pa = "#{BILI_PRO_PATH}rankingSP1\\"
    list1_count = 100
    list2_count = 13
    img_maker = BiliRankingImage.new pa
      csv_file = File.open "#{pa}_list.csv"
      csv_data = CSV::IOReader.new(csv_file)
      data = []
      csv_data.each do |row|
        data << WeeklyResult.new({ :wid => row[2],
                  :name => row[4], :wtype => row[5], :author => row[6],
                  :clicks => row[7], :clicks_rank => row[8], :comments => row[9], :comments_rank => row[10],
                  :stows => row[11], :stows_rank => row[12], :part => row[13],
                  :score => row[1], :score_rank => row[0], :danmu => row[14]
                }) unless row[0].to_i.zero?
        break if data.size>402
      end
      #=========================================================
      date_now =  Time.now
      #data[0...list1_count].each{ |d| img_maker.make_ranking_img1 d }
      img_maker.make_ranking_img2 data[385...400]
      puts "#{Time.now - date_now} second complete"
  end
  desc "Export single"
  task :export_single_to_img_sp => :environment do
    require 'csv'
    require 'lib/tasks/bili_ranking_image_sp.rb'
    pa = "#{BILI_PRO_PATH}rankingSP1\\"
    img_maker = BiliRankingImage.new pa
      csv_file = File.open "#{pa}_list.csv"
      csv_data = CSV::IOReader.new(csv_file)
      index = 0
      weekly_result = nil
      csv_data.each do |row|
        if index == 97
          weekly_result = WeeklyResult.new({ :wid => row[2],
                  :name => row[4], :wtype => row[5], :author => row[6],
                  :clicks => row[7], :clicks_rank => row[8], :comments => row[9], :comments_rank => row[10],
                  :stows => row[11], :stows_rank => row[12], :part => row[13],
                  :score => row[1], :score_rank => row[0], :danmu => row[14]
                })
        break
        end
        index += 1
      end
    img_maker.make_ranking_img1 weekly_result
  end
end
